package cn.edu.zjicm.wordsnet_d.activity;

import java.util.ArrayList;
import java.util.List;

import com.umeng.analytics.MobclickAgent;

import cn.edu.zjicm.wordsnet_d.R;
import cn.edu.zjicm.wordsnet_d.activity.base.WordBaseActivity;
import cn.edu.zjicm.wordsnet_d.adapter.AddSchoolAdapter;
import cn.edu.zjicm.wordsnet_d.util.NightModeUtil;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class HelpCenterActivity extends WordBaseActivity {

	public static void startActivity(Context context) {
		Intent in = new Intent(context, HelpCenterActivity.class);
		context.startActivity(in);
	}

	private ListView mListView;
	private List<String> questions;
	private List<String> answers;

	public static HelpCenterActivity mContext;
	private View footerView;
	private AddSchoolAdapter adapter;
	private Button askBtn;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mContext = HelpCenterActivity.this;
		setContentView(R.layout.activity_help_center);
		setTitleBarStyle(WordBaseActivity.TITLE_BAR_STYLE_BACK_BUTTON);
		setTitleText("帮助中心");

		setBackButton(new OnClickListener() {

			@Override
			public void onClick(View v) {
				toFinish();
			}
		});

		mListView = (ListView) findViewById(R.id.help_center_lv);
		footerView = LayoutInflater.from(mContext).inflate(R.layout.view_help_center_footer, null);
		askBtn = (Button) footerView.findViewById(R.id.ask_btn);
		mListView.addFooterView(footerView);
		initData();
		adapter = new AddSchoolAdapter(this, questions, true);
		mListView.setAdapter(adapter);
		askBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				startActivity(new Intent(HelpCenterActivity.this, FeedBackForUMengActivity.class));
				toFinish();
			}
		});
		mListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				Intent in = new Intent(HelpCenterActivity.this, HelpCenterAnswerActivity.class);
				in.putExtra("question", questions.get(position));
				in.putExtra("answer", answers.get(position));
				startActivity(in);
			}
		});
	}

	private void initData() {
		questions = new ArrayList<String>();
		questions.add(getResources().getString(R.string.help_center_Q1));
		questions.add(getResources().getString(R.string.help_center_Q2));
		questions.add(getResources().getString(R.string.help_center_Q3));
		questions.add(getResources().getString(R.string.help_center_Q4));
		questions.add(getResources().getString(R.string.help_center_Q5));
		questions.add(getResources().getString(R.string.help_center_Q6));
		questions.add(getResources().getString(R.string.help_center_Q7));
		questions.add(getResources().getString(R.string.help_center_Q8));
		questions.add(getResources().getString(R.string.help_center_Q9));
		questions.add(getResources().getString(R.string.help_center_Q10));
		questions.add(getResources().getString(R.string.help_center_Q11));
		questions.add(getResources().getString(R.string.help_center_Q12));

		answers = new ArrayList<String>();
		answers.add(getResources().getString(R.string.help_center_A1));
		answers.add(getResources().getString(R.string.help_center_A2));
		answers.add(getResources().getString(R.string.help_center_A3));
		answers.add(getResources().getString(R.string.help_center_A4));
		answers.add(getResources().getString(R.string.help_center_A5));
		answers.add(getResources().getString(R.string.help_center_A6));
		answers.add(getResources().getString(R.string.help_center_A7));
		answers.add(getResources().getString(R.string.help_center_A8));
		answers.add(getResources().getString(R.string.help_center_A9));
		answers.add(getResources().getString(R.string.help_center_A10));
		answers.add(getResources().getString(R.string.help_center_A11));
		String a12 = getResources().getString(R.string.ZM_Q1) + "\n";
		a12 += getResources().getString(R.string.ZM_A1) + "\n\n";
		a12 += getResources().getString(R.string.ZM_Q2) + "\n";
		a12 += getResources().getString(R.string.ZM_Q4) + "\n";
		a12 += getResources().getString(R.string.ZM_A4) + "\n\n";
		a12 += getResources().getString(R.string.ZM_A2) + "\n\n";
		a12 += getResources().getString(R.string.ZM_Q3) + "\n";
		a12 += getResources().getString(R.string.ZM_A3) + "\n\n";
		
		answers.add(a12);
	}

	@Override
	protected void onResume() {
		super.onResume();
		MobclickAgent.onResume(this);
	}

	@Override
	protected void onPause() {
		super.onPause();
		MobclickAgent.onPause(this);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			toFinish();
			return true;
		}
		return false;
	}

	public void toFinish() {
		finish();
		mContext = null;
	}
}
